#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "proto.h"

#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

int main()
{
    key_t key = ftok(KEYPATH, KEYPROJ);
    proto_st rbuf;

    if (key < 0)
    {
        perror("ftok()");
        exit(1);
    }

    int msgid = msgget(key, 0);
    if (msgid < 0)
    {
        perror("msgget()");
        exit(1);
    }

    rbuf.mtype = 1;
    strcpy(rbuf.name, "sga");
    rbuf.math = rand() % 100;
    rbuf.chinese = rand() % 100;

    if (msgsnd(msgid, &rbuf, sizeof(rbuf) - sizeof(long), 0) < 0)
    {
        perror("msgsnd()");
        exit(1);
    }

    printf("OK!\n");

    exit(0);
}
